/**

 @Name：layuiAdmin 主页示例
 @Author：star1029
 @Site：http://www.layui.com/admin/
 @License：GPL-2

 */
//LAY-duban-table 督办事项          LAY-kpi-table KPI进度    LAY-plan-table 工作计划  LAY-data-table数据看板   LAY-meeting-table会议事项
layui.define(['form','laydate','upload','xmSelect','table'],function(exports){
    var admin = layui.admin;
    var $ = layui.$
        ,form = layui.form
        ,common = layui.common
        ,setter = layui.setter
        ,laydate = layui.laydate
        ,xmSelect = layui.xmSelect
        ,upload = layui.upload
        ,table=layui.table;
    var colsArr;
    var colsArr1;
    var colsArr2;
    var colsArr3;
    var colsArr4;
    var tableHead;//表头字段
    //var tableSearch = {};//全局搜索条件
    var parentJson = {};
    // var userid = sessionid;
    var thecount = 0;
    var arrayi = 0;
    var thearray=new Array();


//	var cam = document.getElementById("checkallmeeting");
//    cam.href= "http:"+setter.host + "unite_platform/meeting_info_detail/toSelect";
//	var cad = document.getElementById("checkallduban");
//    cad.href= "http:"+setter.host + "unite_platform/meeting_info_detail/toSelect";
    var search = [null,null];
    var aa = {};
    /*aa.conditionField = "checkuserid";
    aa.conditionValue =  userid;
    aa.conditionOption = "like";
    aa.logicalOperator="and";
    search[0] = aa;*/
    var bb = {};
    /*	bb.conditionField = "a.flag";
        bb.conditionValue =  10;
        bb.conditionOption = "=";
        bb.logicalOperator="and";
        search[1] = bb;*/

    // timeout_status
    // 超时状态
    // 0 准时
    // 1 超时
    // 2 提早
    colsArr = [																//预约信息
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false  },
        {field: 'supplierNumber', title: '供应商编码',align:'center',sort: true , hide:false },
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false },
        {field: 'estimatedArrivalTime', title: '预约时间',align:'center',sort: true , hide:false },
        {field: 'gdsNumber', title: '送货件数',align:'center',sort: true , hide:false}
    ];

    colsArr2 = [																//已确认订单
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false  },
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false },
        {field: 'confirmArrivalTime', title: '确认时间',align:'center',sort: true , hide:false },
        {field: 'gdsNumber', title: '送货件数',align:'center',sort: true , hide:false},
        {title: '收货人',align:'center',sort: true, templet:function (d){
            if(!d.drivers[0].conReceiver){
                return '查询收货员失败'
            }
            let dri = '';
            for(let re of d.drivers){
                console.log(re)
                dri = re.conReceiver.receiverName + "  "
            }
            return dri
        }},
    ];

    colsArr3 = [																//已确认订单
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false},
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false},
        {title: '开始时间',align:'center',sort: true , hide:false,templet:function (d){
                return d.receiveStartTime
            } },
        {title: '收货进度',align:'center',sort: true , hide:false ,templet:function (d){
                return d.receivePercentage+"%"
            }},
        {title: '收货人',align:'center',sort: true, templet:function (d){
                return d.receiver.receiverName
            }},
    ];



    colsArr4 = [																//收货完成
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false},
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false},
        {title: '收货件数',align:'center',sort: true , hide:false,templet:function (d){
                return d.receiveCount
            } },
        {title: '开始时间',align:'center',sort: true , hide:false ,templet:function (d){
                return d.receiveStartTime
            }},
        {title: '结束时间',align:'center',sort: true , hide:false ,templet:function (d){
                return d.finishTime?d.finishTime:"未结束"

            }},
        // {title: '收货人',align:'center',sort: true, templet:function (d){
        //         return  d.receiver.receiverName
        //     }},
    ];

    colsArr5 = [																//收货异常
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false},
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false},
        {title: '状态',align:'center',sort: true , hide:false,templet:function (d){
               switch (d.receiveStatus) {
                   case 0:
                       return "已完成"
                   case 1:
                       return "正在进行"
                   case 2:
                       return "异常"
               }
            } },
        {title: '异常属性',align:'center',sort: true , hide:false ,templet:function (d){
                if(new Date(d.receiveCompleteTime).getTime() > new Date(d.finishTime).getTime()){
                    return '早到'
                }else{
                    return '迟到'
                }
            }}

    ];


    colsArr6 = [																//预约异常
        {field: '', title: '序号',align:'center' ,type: 'numbers' },
        {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false},
        {field: 'supplierName', title: '供应商名称',align:'center',sort: true , hide:false},
        {title: '异常属性',align:'center',sort: true , hide:false ,templet:function (d){
            console.log(d)
        }}

    ];


    // colsArr2 = [																//正在收货
    //     {field: '', title: '序号',align:'center' ,type: 'numbers' },
    //     {field: 'reservationNumber', title: '预约单号',align:'center',sort: true, hide:false  },
    //     {field: 'orderNumber', title: '订单号',align:'center',sort: true , hide:true },
    //     {field: 'estimatedTimeOfArrival', title: '预计时间',align:'center',sort: true , hide:false },
    //     {field: 'nowStatus', style:'color:red', title: '状态',align:'center',sort: true ,width:100,templet: function(d){
    //             if(d.nowStatus ==0){return '发起预约'}
    //             else if(d.nowStatus==1){return '等待确认'}
    //             else if(d.nowStatus==2){return '预约已确认'}
    //             else if(d.nowStatus==3){return '已发车'}
    //             else if(d.nowStatus==4){return '已到达'}
    //             else if(d.nowStatus==5){return '开始装卸'}
    //             else if(d.nowStatus==6){return '装卸完毕'}
    //             else if(d.nowStatus==7){return '预约已完成'}
    //             else if(d.nowStatus==8){return '预约异常'}
    //             else if(d.nowStatus==9){return '预约取消'}
    //         }
    //     },
    //     {field: 'actualPlatformNumber', title: '预计月台',align:'center',sort: true, templet:function (d){
    //             return d.hasOwnProperty("actualPlatform")?`${d.actualPlatform.platformCode}号月台`:"未定义月台"
    //         } },
    //     // {fixed: 'right',title: '工具',align: 'center' ,toolbar:function (d){
    //     //         // console.log("加载工具栏")
    //     //         // return `<a class="layui-btn layui-btn-xs" lay-event="watch">点击查看</a>`
    //     //         return ` <a class="layui-btn layui-btn-xs" lay-event="gongzuo">工作记录</a>
    //     //                     <a class="layui-btn layui-btn-xs" lay-event="gerenjianli">个人简历 <i class="layui-icon layui-icon-down"></i></a>`
    //     // }}
    // ];



    // colsArr1 = [                                                              //已完成订单
    //     {field: '', title: '序号',align:'center' ,type: 'numbers' },
    //     {field: 'order_number', title: '订单号',align:'center',sort: true , hide:true },
    //     {field: 'actual_time_of_arrival', title: '实际时间',align:'center',sort: true , hide:true },
    //     {field: 'flag', title: '状态',align:'center',sort: true ,width:100,templet: function(d){
    //             if(d.flag==0){return '发起预约'}
    //             else if(d.flag==1){return '等待预约确认'}
    //             else if(d.flag==2){return '预约已确认'}
    //             else if(d.flag==3){return '已发车'}
    //             else if(d.flag==4){return '已到达'}
    //             else if(d.flag==5){return '开始装卸'}
    //             else if(d.flag==6){return '装卸完毕'}
    //             else if(d.flag==7){return '预约已完成'}
    //             else if(d.flag==8){return '预约异常'}
    //             else if(d.flag==9){return '预约取消'}
    //         }
    //     },
    //     {field: 'actual_platform_number', title: '实际月台',align:'center',sort: true, hide:true  },
    //     {field: 'reservation_number', title: '预约单号',align:'center',sort: true, hide:false  },
    // ];
    // colsArr2 = [                                                              //早到车辆
    //     {field: '', title: '序号',align:'center' ,type: 'numbers' },
    //     {field: 'order_number', title: '订单号',align:'center',sort: true , hide:true },
    //     {field: 'actual_time_of_arrival', title: '实际时间',align:'center',sort: true , hide:true },
    //     {field: 'flag', title: '状态',align:'center',sort: true ,width:100,templet: function(d){
    //             if(d.flag==0){return '发起预约'}
    //             else if(d.flag==1){return '等待预约确认'}
    //             else if(d.flag==2){return '预约已确认'}
    //             else if(d.flag==3){return '已发车'}
    //             else if(d.flag==4){return '已到达'}
    //             else if(d.flag==5){return '开始装卸'}
    //             else if(d.flag==6){return '装卸完毕'}
    //             else if(d.flag==7){return '预约已完成'}
    //             else if(d.flag==8){return '预约异常'}
    //             else if(d.flag==9){return '预约取消'}
    //         }
    //     },
    //     {field: 'actual_platform_number', title: '实际月台',align:'center',sort: true, hide:true  },
    //     {field: 'reservation_number', title: '预约单号',align:'center',sort: true, hide:false  },
    // ];
    //
    // //迟到车辆
    // colsArr3 = [
    //     {field: '', title: '序号',align:'center' ,type: 'numbers' },
    //     {field: 'order_number', title: '订单号',align:'center',sort: true , hide:true },
    //     {field: 'actual_time_of_arrival', title: '实际时间',align:'center',sort: true , hide:true },
    //     {field: 'flag', title: '状态',align:'center',sort: true ,width:100,templet: function(d){
    //             if(d.flag==0){return '发起预约'}
    //             else if(d.flag==1){return '等待预约确认'}
    //             else if(d.flag==2){return '预约已确认'}
    //             else if(d.flag==3){return '已发车'}
    //             else if(d.flag==4){return '已到达'}
    //             else if(d.flag==5){return '开始装卸'}
    //             else if(d.flag==6){return '装卸完毕'}
    //             else if(d.flag==7){return '预约已完成'}
    //             else if(d.flag==8){return '预约异常'}
    //             else if(d.flag==9){return '预约取消'}
    //         }
    //     },
    //     {field: 'actual_platform_number', title: '实际月台',align:'center',sort: true, hide:true  },
    //     {field: 'reservation_number', title: '预约单号',align:'center',sort: true, hide:false  },
    // ];




    // colsArr4 = [                                                              //会议事项
    //
    //     {field: 'operation', title: '倒计时(天)',align:'center',width: 95,templet: function(d){
    //             var myDate = new Date();
    //             var days =getDayChaBetween(myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate(),d.shouldlastdate);
    //             days = Math.floor(days);
    //             if(days>=0){
    //                 if(days>3){thecount=thecount+1; return days;}
    //                 else{thearray[arrayi]=thecount; arrayi = arrayi +1 ;thecount=thecount+1; return days;}
    //             }
    //             else{
    //                 thearray[arrayi]=thecount;
    //                 arrayi = arrayi +1 ;
    //                 thecount=thecount+1;
    //                 return 0;
    //             }
    //         }
    //     },
    //     {field: 'operation', title: '操作',align:'center',width: 95,toolbar: '#barDemo' },
    // ];
    layui.each(colsArr,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })
    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.search = search;
    parentJson.headField = tableHead;
    // parentJson.sessionid = sessionid;
    //未完成
    // console.log(parentJson);
    table.render({
        elem: '#LAY-reservation-table'
        ,url: 'reservation/receiveManager/getUncompletedReservation'
        ,cols: [colsArr]
        //,toolbar: 'true'
        //,defaultToolbar: ['print']
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }

    });
    tableHead='';//表头字段
    parentJson = {};


    layui.each(colsArr2,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })

    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.headField = tableHead;
    //已完成
    table.render({
        elem: '#LAY-confirm-table'
        ,url:  'reservation/receiveManager/getConfirmReservation'
        ,cols: [colsArr2]
        //,toolbar: 'true'
        //,defaultToolbar: ['print']
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }
    });
    tableHead='';//表头字段
    parentJson = {};

    layui.each(colsArr3,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })
    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.headField = tableHead;
    // parentJson.sessionid = sessionid;
    //早到
    table.render({
        elem: '#LAY-receive-table'
        // ,url:  'http:'+setter.host + 'unite_platform/reservation/receiveManager/getUnlateReservation'
        ,url:  'reservation/receiveManager/getReceivingReservation'
        ,cols: [colsArr3]
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }
    });
    tableHead='';//表头字段
    parentJson = {};

    layui.each(colsArr4,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })
    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.headField = tableHead;
    //迟到
    table.render({
        elem: '#LAY-received-table'
        ,url:   'reservation/receiveManager/getReceivedReservation'
        ,cols: [colsArr4]
        //,toolbar: 'true'
        //,defaultToolbar: ['print']
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }
    });

    tableHead='';//表头字段
    parentJson = {};

    layui.each(colsArr5,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })
    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.headField = tableHead;
    //迟到
    table.render({
        elem: '#LAY-receiveErr-table'
        ,url:   'reservation/receiveManager/getReceiveErr'
        ,cols: [colsArr5]
        //,toolbar: 'true'
        //,defaultToolbar: ['print']
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }
    });

    tableHead='';//表头字段
    parentJson = {};

    layui.each(colsArr6,function(inx,val){
        tableHead += val.hasOwnProperty('field')?val.field:'-';
        tableHead += ',';
    })
    //tableHead是获取表字段
    tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
    parentJson.headField = tableHead;
    //迟到
    table.render({
        elem: '#LAY-reservationErr-table'
        ,url:   'reservation/receiveManager/getReservationErr'
        ,cols: [colsArr6]
        //,toolbar: 'true'
        //,defaultToolbar: ['print']
        ,method:'get'
        // ,contentType:'application/json; charset=utf-8'
        // ,where:parentJson
        ,height: '350'
        ,text: {
            none: '暂无相关数据'
        }
    });




    table.on('tool(LAY-uncomp-reservation-table)', function(obj){
        // var data = obj.data //获得当前行数据
        // if(obj.event === 'detail'){
        //     if(obj.data.flag==12){
        //         obj.data.bakUrl = setter.host+'unite_platform/reservation/receiveManager/getUncompletedReservation';
        //         obj.data.jsType = 'edit';
                layui.common.postUrl(obj.data,setter.host+'unite_platform/meeting_info_detail/huifu');
            // }else{
            //     obj.data.bakUrl = setter.host+'unite_platform/meeting_info_detail/toSelect';
            //     obj.data.jsType = 'edit';
            //     layui.common.postUrl(obj.data,setter.host+'unite_platform/meeting_info_detail/tosearchreply');//toSearch
            // }
            //

        // }

        // //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        // var data = obj.data //获得当前行数据
        //     ,layEvent = obj.event; //获得 lay-event 对应的值
        //
        // console.log(data.id)
        // layer.open({
        //     type: 1
        //     ,title: '工作记录'
        //     ,content: '<div class="layui-container" style="width: 98%"><table id="LAY-human-gzjl" lay-filter="LAY-human-gzjl" class=""></table></div>'
        //     ,shadeClose: true//开启遮罩关闭
        //     ,area: ['70%', '90%']
        //     ,maxmin: true
        //     ,btn: ['确定']
        //     ,success: function(layero, index){
        //         //     var body=layer.getChildFrame('body',index);//少了这个是不能从父页面向子页面传值的
        //         //     //获取子页面的元素，进行数据渲染
        //         // console.log(body)
        //         //     body.contents().find("#user_id").val(data.id);
        //
        //
        //         table.render({
        //             elem: '#LAY-human-gzjl'  // 弹出层表格id
        //             ,url: setter.host + '/human/menu/getGongzuo' // 后端请求URL地址
        //             ,method: 'post'
        //             ,where: {'headField':'gz_start,gz_over,gz_bumen,gz_gangwei','user_id':data.id}
        //             ,page: true
        //             ,contentType:"application/json; charset=utf-8"
        //             ,cols: [[
        //                 {field: 'gz_start', title: '开始日期',sort:true,align:'center'},
        //                 {field: 'gz_over', title: '结束日期',sort:true,align:'center'},
        //                 {field: 'gz_bumen', title: '部门',sort:true,align:'center',width: 100, sort: true,},
        //                 {field: 'gz_gangwei', title: '岗位',align:'center',sort:true,sort: true,width: 130,},
        //             ]]
        //         })
        //     }
        //     ,yes: function(index, layero){
        //         layer.close(index)
        //     }
        // });



    });



    exports('mainPage', {})
    function  getDayChaBetween(date1,date2){
        var  startDate = Date.parse(date1);
        var  endDate = Date.parse(date2);
        var days=(endDate - startDate)/(1*24*60*60*1000);
        // alert(days);
        return  days;
    }


    function Layui_SetDataTableRowColor(TabDivId,RowIndex, ColorString)
    {
        try
        {
            var div = document.getElementById(TabDivId);
            if(div != null) //找到对象了
            {
                var table_main = div.getElementsByClassName('layui-table-main');  //通过class获取table_main
                if (table_main != null && table_main.length > 0)
                {
                    var table = table_main[0].getElementsByClassName('layui-table');  //通过class获取table
                    if (table != null && table.length > 0) {

                        var trs = table[0].querySelectorAll("tr");
                        if (trs != null && trs.length > 0) {

                            trs[RowIndex].style.color = ColorString;
                        }
                    }
                }

            }
        }
        catch(e)
        {
            console.log(e.message);
        }
    }

});